#!/bin/sh
# postinst script for svnyoungest
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

package=playsms
webserver=apache2
webuser=www-data
installpath=/usr/share/$package
binpath=$installpath/bin
dbinfo=/etc/$package/dbinfo.php

logger "$package postinst args: $@"

# start up debconf and dbconf-common
#
. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst.mysql

# first version that started using dbconfig-common
dbc_first_version="0.8.3"

# tell dbconf to generate a config file for the database
dbc_generate_include=php:$dbinfo

# run dbconf-common
dbc_go $package $@


if [ "$1" = "configure" ]; then
     logger "$package upgrading from $2"

     # remove the obsolete cron files
     # from the old version
     #
	 if [ "$2" = "0.8.2" ]; then
        rm -rf /etc/cron.hourly/$package-hourly /etc/cron.daily/$package-daily
        rm -rf /etc/cron.weekly/$package-weekly /etc/cron.monthly/$package-monthly
	 	rm -rf /etc/$package/cron
	 fi

     # give apache user sudo rights for our scripts
     # by adding the webuser to the sudoers file, but
     # make sure we haven't already done so in some past install
     #
     webuser_sudo="$webuser ALL=NOPASSWD: $binpath/*"
     set +e
     grep -q "$webuser_sudo" /etc/sudoers
     ret=$?
     set -e
     if [ "$ret" != "0" ]; then
        echo "\n\n$webuser_sudo" >> /etc/sudoers
     fi

     # make sure we can read the database info
     #
	 chown www-data $dbinfo

     # add the kannel user to group 'dialout'
     # so that it can use bluetooth devices
     # that have been bound to /dev/rfcomm*,
     # which are usually root:dialout
     #
     adduser --quiet kannel dialout

     # reload services whose confs we've modified
     #
	 logger "restarting apache, kannel, cron..."
     if [ -x /usr/sbin/invoke-rc.d ]; then
          invoke-rc.d $webserver reload || true
          invoke-rc.d kannel restart || true
          invoke-rc.d cron restart || true
     else
          /etc/init.d/$webserver reload || true
          /etc/init.d/kannel restart || true
          /etc/init.d/cron restart || true
     fi   


     # quit debconf
     #
     db_stop
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


